home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / STRINGF.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  3KB  |  116 lines

  1. ;*********************************;
  2. ; WASM Far String Module          ;
  3. ; By Eric Tauck                   ;
  4. ;                                 ;
  5. ; Defines:                        ;
  6. ;                                 ;
  7. ;   StrLenF  return string length ;
  8. ;   StrCpyF  copy string          ;
  9. ;   StrCmpF  compare two strings  ;
  10. ;*********************************;
  11.  
  12.         jmps    _stringf_end
  13.  
  14. ;========================================
  15. ; Determine the length of a string.
  16. ;
  17. ; In: DX:AX= string address.
  18. ;
  19. ; Out: AX= length.
  20.  
  21. StrLenF PROC    NEAR
  22.         push    di
  23.         push    es
  24.         mov     di, ax          ;address
  25.         mov     es, dx
  26.         sub     al, al          ;byte to scan for
  27.         mov     cx, 0FFFFH      ;byte to scan
  28.         cld                     ;forward direction
  29.         repne
  30.         scasb                   ;scan for zero
  31.         mov     ax, cx          ;remaining bytes
  32.         inc     ax
  33.         inc     ax              ;adjust
  34.         neg     ax              ;byte count
  35.         pop     es
  36.         pop     di
  37.         ret
  38.         ENDP
  39.  
  40. ;========================================
  41. ; Copy a string to a new address.
  42. ;
  43. ; In: DX:AX= source address; CX:BX=
  44. ;     destination address.
  45. ;
  46. ; Out: AX= length of string copied.
  47.  
  48. StrCpyF PROC    NEAR
  49.         push    di
  50.         push    si
  51.         push    ds
  52.         push    es
  53.         mov     si, ax          ;load source
  54.         mov     ds, dx
  55.         mov     di, bx          ;load destination
  56.         mov     es, cx
  57.         mov     ax, si
  58.         cld                     ;forward direction
  59. _srcpf1 movsb                   ;copy byte
  60.         cmp     BYTE [si-1], 0  ;check if end of string
  61.         jnz     _srcpf1         ;loop back if not
  62.         sub     ax, si          ;offset difference
  63.         neg     ax              ;adjust
  64.         dec     ax              ;don't count NUL
  65.         pop     es
  66.         pop     ds
  67.         pop     si
  68.         pop     di
  69.         ret
  70.         ENDP
  71.  
  72. ;========================================
  73. ; Compare two strings.
  74. ;
  75. ; In: DX:AX= string one; CX:BX= string
  76. ;     two.
  77. ;
  78. ; Out: CY= set if different.
  79.  
  80. StrCmpF PROC    NEAR
  81.         push    di
  82.         push    si
  83.         push    ds
  84.         push    es
  85.         mov     si, ax          ;string one
  86.         mov     ds, dx
  87.         mov     di, bx          ;string two
  88.         mov     es, cx
  89.         cld                     ;forward direction
  90.  
  91. ;--- loop for each byte
  92.  
  93. _srcmf1 cmpsb                   ;compare bytes
  94.         jne     _srcmf2         ;jump if not same
  95.         cmp     BYTE [si-1], 0  ;check if end of string
  96.         jnz     _srcmf1         ;loop back if not
  97.  
  98. ;--- matched
  99.  
  100.         pop     es
  101.         pop     ds
  102.         pop     si
  103.         pop     di
  104.         clc
  105.         ret
  106.  
  107. ;--- no match
  108.  
  109. _srcmf2 pop     si
  110.         pop     di
  111.         stc
  112.         ret
  113.         ENDP
  114.  
  115. _stringf_end
  116.